package com.imti.contentproviderdemo;

import android.content.ContentValues;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.io.File;

public class MainActivity extends AppCompatActivity
{

    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initDate();

        File downloadRoot = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DOWNLOADS);
    }

    private void initDate()
    {
        ContentValues cv = new ContentValues();
        cv.put("stu_name", "张三");
        cv.put("stu_class", "Android");
        cv.put("stu_company", "Alibaba");

        //Uri ContentProvider暴露给外部的Uri，
        //以及ContentValues对象
        Uri newlyInsertItemUri =
            getContentResolver().insert(StuUri.ADD_STUDENT, cv);

        Log.d(TAG, "新插入的最新一条数据："
                       + newlyInsertItemUri.toString());
    }
}